﻿/* Muaz Khan – http://dashingquill.web.officelive.com */
using System;
using System.Linq;

namespace DTweet.Helpers
{
    public class RandomNumbers
    {
        /***********************************
         * unique identifier for user - i.e. UserToken
         ***********************************/
        internal static string GetRandomNumbers(int length = 6)
        {
            var values = new byte[length];
            var rnd = new Random();
            rnd.NextBytes(values);
            return values.Aggregate(string.Empty, (current, v) => current + v.ToString());
        }

        private static string _SecurityTokenForAccountDeleteRequest;

        public static int RequestsCount = 0;

        public static string SecurityTokenForAccountDeleteRequest
        {
            get
            {                
                if (RequestsCount >= 2)
                {
                    RequestsCount = 0;
                    _SecurityTokenForAccountDeleteRequest = null;
                    return null;
                }
                else
                {
                    if (RequestsCount == 0) _SecurityTokenForAccountDeleteRequest = GetRandomNumbers();
                    RequestsCount++;
                    return _SecurityTokenForAccountDeleteRequest;
                }
            }
        }
    }
}